/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UdioCustomer.java
 *
 * Created on Nov 19, 2011, 4:31:23 PM
 */

import java.sql.*;
/**
 *
 * @author Pat, Jamie, Kazu, Steven, and Shaoyan
 */
public class UdioCustomer extends javax.swing.JFrame {

    private static String username;
    private static int custID;
    private static int startTime = 0;
    private static int endTime = 0;
    private static int numHours;
    private static int vehicleClass = 0;
    private static int pickup = 0;
    private static int dropoff = 0;
    private static double balance = 0.;
    private static String date;
    private static int timeFlag = -1;
    private static int status;
    private static String[] custInfo;
    private static String custName;
    private static String custPhone;
    private static String custAddress;
    private static String custEmail;
    Customer _cust;
    Booking _booking;
    Billing _billing;
    Depot _depot;
    Vehicle _vehicle;

    /** Creates new form UdioCustomer
     * @param username 
     */
    public UdioCustomer(String username) {
        initComponents();
        jLabel7.setVisible(false);
        jLabel8.setVisible(false);
        jLabel12.setVisible(false);
        
        jLabel13.setVisible(false);
        jLabel14.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
        jLabel19.setVisible(false);
        jLabel20.setVisible(false);
        jLabel21.setVisible(false);
        jLabel22.setVisible(false);
        jLabel23.setVisible(false);
        jLabel24.setVisible(false);
        jLabel25.setVisible(false);
        jLabel26.setVisible(false);
        jLabel27.setVisible(false);
        
        this.username = username;
        
        this._cust = new Customer();
        this._booking = new Booking();
        this._billing = new Billing();
        this._depot = new Depot();
        this._vehicle = new Vehicle();
        
        custID = _cust.getCustomerId(username);
        updateTables();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jDialog1 = new javax.swing.JDialog();
        jFrame2 = new javax.swing.JFrame();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel42 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel40 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jComboBox5 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel31 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel37 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();

        org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jDialog1Layout = new org.jdesktop.layout.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jFrame2Layout = new org.jdesktop.layout.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Booking ID", "Customer ID", "Vehicle ID", "Pickup Depot ID", "Return Depot ID", "Vehicle Class", "Booking Date", "Start Time", "End Time"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel28.setText("Your Next Booking:");

        jLabel29.setText("Welcome Back");

        jLabel30.setText("jLabel30");

        jLabel33.setText("Outstanding Balance:");

        jLabel34.setText("jLabel34");

        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel35.setText("Customer Info");

        jLabel36.setText("Contact Number:");

        jLabel38.setText("Address:");

        jButton4.setText("Update");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        jLabel42.setText("eMail:");

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel35)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(jLabel36)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                                .add(jButton4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 94, Short.MAX_VALUE))
                            .add(jTextField4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)))
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(jLabel38)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE))
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(jLabel42)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel35)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel36)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel38)
                    .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel42)
                    .add(jTextField6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(jButton4)
                .addContainerGap(61, Short.MAX_VALUE))
        );

        jLabel40.setText("Remaining Hours in Membership:");

        jLabel41.setText("jLabel41");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 761, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
                                .add(jLabel29)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel30))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel28)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 761, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel33)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel34))
                        .add(255, 255, 255))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel40)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel41)
                        .addContainerGap(746, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel29))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel28)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel33)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel34)
                .add(18, 18, 18)
                .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel40)
                    .add(jLabel41))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Home", jPanel1);

        jLabel1.setText("Customer ID:");

        jLabel2.setText("#");

        jLabel3.setText("Date:");

        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField1.setText("YYYY-MM-DD");

        jLabel4.setText("Start Time:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---  ", "  4:00 AM", "  5:00 AM", "  6:00 AM", "  7:00 AM", "  8:00 AM", "  9:00 AM", "10:00 AM", "11:00 AM", "12:00 PM", "  1:00 PM", "  2:00 PM", "  3:00 PM", "  4:00 PM", "  5:00 PM", "  6:00 PM", "  7:00 PM", "  8:00 PM", "  9:00 PM", "10:00 PM", "11:00 PM" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel5.setText("End Time:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---", "  5:00 AM", "  6:00 AM", "  7:00 AM", "  8:00 AM", "  9:00 AM", "10:00 AM", "11:00 AM", "12:00 PM", "  1:00 PM", "  2:00 PM", "  3:00 PM", "  4:00 PM", "  5:00 PM", "  6:00 PM", "  7:00 PM", "  8:00 PM", "  9:00 PM", "10:00 PM", "11:00 PM", "12:00 AM" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel6.setText("Number of Hours:");

        jLabel7.setText("#");

        jLabel8.setForeground(new java.awt.Color(204, 0, 0));
        jLabel8.setText("Invalid Time Entered!");

        jLabel9.setText("Vehicle Class:");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---", "Subcompact Car", "Compact Car", "Midsize Car", "Large Car", "Performance Car", "Compact SUV", "Midsize SUV", "Large SUV", " Compact Pickup", "Large Pickup", "Minivan" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jLabel10.setText("Pickup Depot:");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---", "Downtown", "Esquimalt ", "Jubilee", "Uptown", "University" }));
        jComboBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox4ActionPerformed(evt);
            }
        });

        jLabel11.setText("Drop-off Depot:");

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---", "Downtown", "Esquimalt ", "Jubilee", "Uptown", "University" }));
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });

        jButton1.setText("Submit");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Reset");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel12.setForeground(new java.awt.Color(204, 0, 0));
        jLabel12.setText("Missing Fields!");

        jLabel13.setText("Booking Successful!");

        jLabel14.setText("Date:");

        jLabel15.setText("Start Time:");

        jLabel16.setText("End Time:");

        jLabel17.setText("Number of Hours:");

        jLabel18.setText("Vehicle Class:");

        jLabel19.setText("Pickup Depot:");

        jLabel20.setText("Drop-off Depot:");

        jLabel21.setText("jLabel21");

        jLabel22.setText("jLabel22");

        jLabel23.setText("jLabel23");

        jLabel24.setText("jLabel24");

        jLabel25.setText("jLabel25");

        jLabel26.setText("jLabel26");

        jLabel27.setText("jLabel27");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(167, 167, 167)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel5)
                    .add(jLabel4)
                    .add(jLabel3)
                    .add(jLabel1)
                    .add(jLabel6))
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel2Layout.createSequentialGroup()
                            .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(jPanel2Layout.createSequentialGroup()
                                    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(jLabel11))
                                .add(jPanel2Layout.createSequentialGroup()
                                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(jLabel10))
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()
                                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(141, 141, 141)
                                    .add(jLabel9)))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jComboBox5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jComboBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jComboBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                            .add(jLabel7)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jLabel8)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 291, Short.MAX_VALUE)
                            .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jPanel2Layout.createSequentialGroup()
                                    .add(24, 24, 24)
                                    .add(jLabel12))
                                .add(jPanel2Layout.createSequentialGroup()
                                    .add(jButton1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jButton2)))
                            .add(4, 4, 4)))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 547, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(167, 167, 167))
            .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1028, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(468, Short.MAX_VALUE)
                .add(jLabel13)
                .add(432, 432, 432))
            .add(jPanel2Layout.createSequentialGroup()
                .add(166, 166, 166)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel16)
                    .add(jLabel15)
                    .add(jLabel14)
                    .add(jLabel17))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel21)
                            .add(jLabel22)
                            .add(jLabel23))
                        .add(234, 234, 234)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(jLabel20)
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(15, 15, 15)
                                .add(jLabel19))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()
                                .add(16, 16, 16)
                                .add(jLabel18)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel27)
                            .add(jLabel26)
                            .add(jLabel25)))
                    .add(jLabel24))
                .addContainerGap(292, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9)
                    .add(jComboBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10)
                    .add(jComboBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel11)
                    .add(jComboBox5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel6)
                            .add(jLabel8)
                            .add(jLabel7)))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButton1)
                            .add(jButton2))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel12)
                .add(19, 19, 19)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel14)
                            .add(jLabel21))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel15)
                            .add(jLabel22))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel16)
                            .add(jLabel23))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel17)
                            .add(jLabel24)))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel18)
                            .add(jLabel25))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel19)
                            .add(jLabel26))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel20)
                            .add(jLabel27))))
                .addContainerGap(144, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Book Vehicle", jPanel2);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Booking ID", "Customer ID", "Vehicle ID", "Pickup Depot", "Return Depot", "Vehicle Class", "Booking Date", "Start Time", "End Time"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jLabel31.setText("Date Range:");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel32.setText("to");

        jButton3.setText("Cancel Booking");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton5.setText("Update Range");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel31)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel32)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton5))
                    .add(jButton3))
                .add(245, 245, 245))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel31)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel32)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton5))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 188, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton3)
                .addContainerGap(256, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("View Booking", jPanel3);

        jLabel37.setText("Current Balance:");

        jLabel39.setText("jLabel39");

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Bill ID", "Start Date", "End Date", "Due Date", "Amount Due", "Paid?"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTable3);

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 539, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel37)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel39, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 891, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(18, 18, 18)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(29, 29, 29)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel37)
                    .add(jLabel39))
                .addContainerGap(273, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("View Bill", jPanel4);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1032, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {
        int _id = Integer.parseInt(jTable2.getValueAt(jTable2.getSelectedRow(),0).toString());
        System.out.println("Delete booking ID "+_id);
        CancelPopUp popup = new CancelPopUp();
        popup.bookid = _id;
        popup.user = 0;
        popup.udio = this;
        int policy = _booking.checkCancelRights(_id);
        if(policy == 0){
            popup.setText(" ");
            popup.setText2("Are you sure?");
        } 
        else if(policy == 1){
            popup.setText("There will be a 50% penalty if you cancel now.");
            popup.setText2("Are you sure?");
        }else if(policy== 2){
            popup.setText("There will be a 75% penalty if you cancel now.");
            popup.setText2("Are you sure?");
        }
        else{
            popup.setText("There will be a 100% penalty if you cancel now.");
            popup.setText2("Are you sure?");
        }    
        popup.setVisible(true);
        //this.setVisible(false);
        
       //_booking.removeBooking(_id);
    } catch (Exception e) {
        System.out.println("No row selected!");
        return;
    }
    updateTables();
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    jTextField1.setText("YYYY-MM-DD");
    jComboBox1.setSelectedIndex(0);
    jComboBox2.setSelectedIndex(0);
    jComboBox3.setSelectedIndex(0);
    jComboBox4.setSelectedIndex(0);
    jComboBox5.setSelectedIndex(0);
    
    jLabel13.setVisible(false);
    jLabel14.setVisible(false);
    jLabel15.setVisible(false);
    jLabel16.setVisible(false);
    jLabel17.setVisible(false);
    jLabel18.setVisible(false);
    jLabel19.setVisible(false);
    jLabel20.setVisible(false);
    jLabel21.setVisible(false);
    jLabel22.setVisible(false);
    jLabel23.setVisible(false);
    jLabel24.setVisible(false);
    jLabel25.setVisible(false);
    jLabel26.setVisible(false);
    jLabel27.setVisible(false);
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
    jLabel13.setText("Booking Status");
    jLabel21.setVisible(false);
    jLabel22.setVisible(false);
    jLabel23.setVisible(false);
    jLabel24.setVisible(false);
    jLabel25.setVisible(false);
    jLabel26.setVisible(false);
    jLabel27.setVisible(false);
    
    date = jTextField1.getText(); 
    jLabel12.setVisible(false);
    BookingManager bm = new BookingManager();

    if (numHours <= 0 || vehicleClass == 0 || pickup == 0 || dropoff == 0 || date.equals("YYYY-MM-DD") || timeFlag == -1) {
        jLabel12.setVisible(true);
    } else {
        jLabel12.setVisible(false);
        status = bm.bookVehicle(custID, pickup, dropoff, vehicleClass, date, startTime, numHours);
    }
    
    System.out.println("cust id = " + custID);
    System.out.println("pickup id = " + pickup);
    System.out.println("dropoff id = " + dropoff);
    System.out.println("vehicleClass = " + vehicleClass);
    System.out.println("date = " + date);
    System.out.println("start time = " + startTime);
    System.out.println("End time = " + endTime);
    System.out.println("num hours = " + numHours);
    
    if (status == 1) {
        
        System.out.println("*****");
        System.out.println("cust id = " + custID);
        System.out.println("pickup id = " + pickup);
        System.out.println("dropoff id = " + dropoff);
        System.out.println("vehicleClass = " + vehicleClass);
        System.out.println("date = " + date);
        System.out.println("start time = " + startTime);
        System.out.println("End time = " + endTime);
        System.out.println("num hours = " + numHours);
        
        jLabel13.setVisible(true);
        jLabel13.setText("Booking Successful!");
        jLabel8.setVisible(false);
        
        jLabel21.setText(date);
        jLabel22.setText(Integer.toString(startTime) + ":00");
        jLabel23.setText(Integer.toString(endTime) + ":00");
        jLabel24.setText(Integer.toString(numHours));
        
        //Vehicle veh = new Vehicle();
        jLabel25.setText(_vehicle.getVehicleType(vehicleClass));
        
        //Depot dep = new Depot();
        jLabel26.setText(_depot.getDepotName(pickup));
        jLabel27.setText(_depot.getDepotName(dropoff));

        jLabel14.setVisible(true);
        jLabel15.setVisible(true);
        jLabel16.setVisible(true);
        jLabel17.setVisible(true);
        jLabel18.setVisible(true);
        jLabel19.setVisible(true);
        jLabel20.setVisible(true);    
        jLabel21.setVisible(true);
        jLabel22.setVisible(true);
        jLabel23.setVisible(true);
        jLabel24.setVisible(true);
        jLabel25.setVisible(true);
        jLabel26.setVisible(true);
        jLabel27.setVisible(true);
        
        // reset fields
        jTextField1.setText("YYYY-MM-DD");
        jComboBox1.setSelectedIndex(0);
        jComboBox2.setSelectedIndex(0);
        jComboBox3.setSelectedIndex(0);
        jComboBox4.setSelectedIndex(0);
        jComboBox5.setSelectedIndex(0);
    
        updateTables();
    } else {
        
        jLabel13.setVisible(true);
        if (status==-1)
            jLabel13.setText("Booking Failed (Start time must be before end time!)");
        else if (status==-2)
            jLabel13.setText("Booking Failed (Not enough remaining hours!)");
        else if (status==-3)
            jLabel13.setText("Booking Failed (No vehicle available for that time slot!)");
        else if (status==-4)
            jLabel13.setText("Booking Failed (DB error!)");
        else
            jLabel13.setText("Booking Failed! (Unknown error!)");
        
        jLabel21.setText(date);
        jLabel22.setText(Integer.toString(startTime) + ":00");
        jLabel23.setText(Integer.toString(endTime) + ":00");
        jLabel24.setText(Integer.toString(numHours));
        
        //Vehicle veh = new Vehicle();
        jLabel25.setText(_vehicle.getVehicleType(vehicleClass));
        
        //Depot dep = new Depot();
        jLabel26.setText(_depot.getDepotName(pickup));
        jLabel27.setText(_depot.getDepotName(dropoff));

        jLabel14.setVisible(true);
        jLabel15.setVisible(true);
        jLabel16.setVisible(true);
        jLabel17.setVisible(true);
        jLabel18.setVisible(true);
        jLabel19.setVisible(true);
        jLabel20.setVisible(true);
        jLabel21.setVisible(true);
        jLabel22.setVisible(true);
        jLabel23.setVisible(true);
        jLabel24.setVisible(true);
        jLabel25.setVisible(true);
        jLabel26.setVisible(true);
        jLabel27.setVisible(true);
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed
    dropoff = jComboBox5.getSelectedIndex();
}//GEN-LAST:event_jComboBox5ActionPerformed

private void jComboBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox4ActionPerformed
    pickup = jComboBox4.getSelectedIndex();
}//GEN-LAST:event_jComboBox4ActionPerformed

private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
    vehicleClass = jComboBox3.getSelectedIndex();
}//GEN-LAST:event_jComboBox3ActionPerformed

private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
    startTime = jComboBox1.getSelectedIndex();
    endTime = jComboBox2.getSelectedIndex();
    
    if (jComboBox1.getSelectedIndex() == 0)
        startTime = 0;
    else
        startTime = startTime + 3;
    
    if (jComboBox2.getSelectedIndex() == 0)
        endTime = 0;
    else
        endTime = endTime + 4;
    
    if (startTime != 0 && endTime != 0)
        numHours = endTime - startTime;
    else
        numHours = 0;
    
    if (numHours <= 0) {
        jLabel7.setVisible(false);
        jLabel8.setVisible(true);
        timeFlag = -1;
    } else {
        jLabel7.setVisible(true);
        jLabel8.setVisible(false);
        jLabel7.setText(Integer.toString(numHours));
        timeFlag = 0;
    }
}//GEN-LAST:event_jComboBox2ActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    startTime = jComboBox1.getSelectedIndex();
    endTime = jComboBox2.getSelectedIndex();
    
    if (jComboBox1.getSelectedIndex() == 0)
        startTime = 0;
    else
        startTime = startTime + 3;
    
    if (jComboBox2.getSelectedIndex() == 0)
        endTime = 0;
    else
        endTime = endTime + 4;
    
    if (startTime != 0 && endTime != 0)
        numHours = endTime - startTime;
    else
        numHours = 0;
    
    if (numHours <= 0) {
        jLabel7.setVisible(false);
        jLabel8.setVisible(true);
        timeFlag = -1;
    } else {
        jLabel7.setVisible(true);
        jLabel8.setVisible(false);
        jLabel7.setText(Integer.toString(numHours));
        timeFlag = 0;
    }
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    String _tempBeginDate = jTextField2.getText();
    String _tempEndDate = jTextField3.getText();
    _tempBeginDate = _tempBeginDate.replace("-", "");
    _tempEndDate   = _tempEndDate.replace("-", "");
    if((_tempBeginDate.length()!= 8)||(_tempEndDate.length()!=8)) {
        System.out.println("Incorrect strlen");
        return;
    }
    int _start, _end = 0;
    try {
        _start = Integer.parseInt(_tempBeginDate);
        _end = Integer.parseInt(_tempEndDate);
    } catch(NumberFormatException nfe){
        System.out.println("Not a valid date");
        return;
    }
    String[][] _rangeBookings = _booking.getCustomerBookingsInRange(custID, _start, _end);
    updateTableFromRange(_rangeBookings);
}//GEN-LAST:event_jButton5ActionPerformed

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField2ActionPerformed

//handle updating customer info
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        System.out.println("Update Contact Info");
        String _phone = jTextField4.getText();
        String _address = jTextField5.getText();
        String _email = jTextField6.getText();

        try {
            _cust.updateCustomerContactInfo(custID, _email, _address, _phone);
        } catch (Exception ec){
            System.out.println(ec+"Update Customer Info Failed");
        }
        updateTables();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

private void updateTableFromRange(String[][] _range){
    if(_range == null){
        System.out.println("No Bookings in Range");
        return;
    }
    
    //Clearing the "View Booking" table before re-populating it
    for( int nRow = 0 ; nRow < jTable2.getRowCount() ; nRow++ ){
        for( int nColumn = 0 ; nColumn < jTable2.getColumnCount(); nColumn++ ){
            jTable2.setValueAt("" , nRow , nColumn ); 
        }
    }
    
    int i = 0;
    int j = 0;
    while (i < 10){
        if(_range[i][0] != null){
            jTable2.setValueAt(_range[i][0], i, 0);
            jTable2.setValueAt(custID, i, 1);
            jTable2.setValueAt(_range[i][2], i, 2);
            jTable2.setValueAt(_depot.getDepotName(Integer.parseInt(_range[i][3])), i, 3);
            jTable2.setValueAt(_depot.getDepotName(Integer.parseInt(_range[i][4])), i, 4);
            jTable2.setValueAt(_vehicle.getVehicleType(Integer.parseInt(_range[i][5])), i, 5);
            jTable2.setValueAt(_range[i][6], i, 6);
            jTable2.setValueAt(_range[i][7]+":00", i, 7);
            jTable2.setValueAt(_range[i][8]+":00", i, 8);
        } else {
            for(j=0;j<9;j++){
                jTable2.setValueAt("", i, j);
            }
        }
        i++;
    }
}

public void updateTables()
{
    //Booking _booking = new Booking();
    //Customer _cust = new Customer();
    //Depot _depot = new Depot();
    
    //Clearing the "View Booking" table before re-populating it
    for( int nRow = 0 ; nRow < jTable2.getRowCount() ; nRow++ ){
        for( int nColumn = 0 ; nColumn < jTable2.getColumnCount(); nColumn++ ){
            jTable2.setValueAt("" , nRow , nColumn ); 
        }
    }
    
    custInfo = _cust.getCustomerInfo(custID);
    custName = custInfo[3];
    if(custInfo[4]!=null){
        numHours = Integer.parseInt(custInfo[4]);
    } else {
        updateTables();
    }
    custAddress = custInfo[8];
    custPhone = custInfo[9];
    custEmail = custInfo[7];
    
    jLabel30.setText(custName+"!");

    jTextField4.setText(custPhone);
    jTextField5.setText(custAddress);
    jTextField6.setText(custEmail);
    jLabel41.setText(Integer.toString(numHours));
    jLabel2.setText(Integer.toString(custID));
    
    String[] _bookingInfo = _booking.getNextBookingInfo(custID);
    if(_bookingInfo != null){ //nullchecks ahoy....
        for(int i=0; i<3; i++){
            //System.out.println(i+": "+_bookingInfo[i]);
            jTable1.setValueAt(_bookingInfo[i],0,i);
        }

        for(int i=3; i<5; i++){
            int temp = 0;
            //System.out.println(i +": "+_bookingInfo[i]);
            if(!_bookingInfo[i].equals("")){
                temp = Integer.parseInt(_bookingInfo[i]);
                jTable1.setValueAt(_depot.getDepotName(temp), 0, i);
            }
        }

        //Vehicle _veh = new Vehicle();
        //System.out.println("5: "+_bookingInfo[5]);
        if(!_bookingInfo[5].equals("")){
            int temp = Integer.parseInt(_bookingInfo[5]);
            jTable1.setValueAt(_vehicle.getVehicleType(temp), 0, 5);
        }

        //System.out.println("6: "+_bookingInfo[6]);
        jTable1.setValueAt(_bookingInfo[6],0,6);

        //System.out.println("7: "+_bookingInfo[7]);
        jTable1.setValueAt(_bookingInfo[7]+":00",0,7);

        //System.out.println("8: "+_bookingInfo[8]);
        jTable1.setValueAt(_bookingInfo[8]+":00",0,8);
    }
    
    // Something big and long to fully populate the bookings table
    ResultSet _bookings = _booking.getCustomerBookings(custID);
    try {
        int i=0;
        while (_bookings.next()) {
            jTable2.setValueAt(_bookings.getInt("bookingId"), i, 0);
            jTable2.setValueAt(custID, i, 1);
            jTable2.setValueAt(_bookings.getInt("vehicleId"), i, 2);
            jTable2.setValueAt(_depot.getDepotName(_bookings.getInt("pickupDepotId")), i, 3);
            jTable2.setValueAt(_depot.getDepotName(_bookings.getInt("returnDepotId")), i, 4);
            jTable2.setValueAt(_vehicle.getVehicleType(_bookings.getInt("vehicleClass")), i, 5);
            jTable2.setValueAt(_bookings.getDate("bookingDate"), i, 6);
            jTable2.setValueAt(_bookings.getInt("bookingStartTime"), i, 7);
            jTable2.setValueAt(_bookings.getInt("bookingEndTime"), i, 8);
            i++;
        }
    } catch (Exception e) {}
    
    // Something big and long to fully populate the billing table
    ResultSet _bills = _billing.getBills(custID);
    try {
        int i=0;
        while (_bills.next()) {
            jTable3.setValueAt(_bills.getInt("billingId"), i, 0);
            jTable3.setValueAt(_bills.getDate("billingStartDate"), i, 1);
            jTable3.setValueAt(_bills.getDate("billingEndDate"), i, 2);
            jTable3.setValueAt(_bills.getDate("billingDueDate"), i, 3);
            jTable3.setValueAt(_bills.getDouble("billAmount"), i, 4);
            int paid = _bills.getInt("paid");
            if (paid == 0)
                jTable3.setValueAt("No", i, 5);
            else
                jTable3.setValueAt("Yes", i, 5);
            i++;
        }
    } catch (Exception e) {}
    
    // Update balance when we refresh the tables
    balance = _billing.getBalance(custID);
    jLabel34.setText("$"+Double.toString(balance));
    jLabel39.setText("$"+Double.toString(balance));
}
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UdioCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UdioCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UdioCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UdioCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new UdioCustomer(username).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    // End of variables declaration//GEN-END:variables
}
